refactor(architecture): separate server, test, and pure utils to fix CI errors#96
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a major architectural refactoring to resolve persistent "module is already linked" errors in CI tests. It establishes clear boundaries between server infrastructure, test utilities, and pure utilities, preventing test code from importing and initializing production server components like Sentry.
Beyond fixing the CI failures, this change significantly improves code quality by eliminating over 580 lines of duplicated code, standardizing environment variables, and resolving numerous TypeScript and ESLint errors.
Background/Details
Since the Sentry v10 integration, our CI pipeline has been plagued by 74 "module is already linked" errors, occurring exclusively on the Ubuntu runner. The root cause was an architectural flaw where our central
src/utils/index.tsbarrel file exported both test utilities and production server code.This created a problematic import chain:
Tests →
src/utils/index.ts→src/server/code → Sentry InstrumentationAs a result, test suites inadvertently initialized the entire server stack, leading to module loading conflicts within Vitest's
vmThreadsenvironment on Linux.Solution
This PR implements a robust, multi-faceted solution:
Architectural Separation:
src/server/: A new dedicated directory for all server-side infrastructure, includingtool-registry.ts,dynamic-tools.ts,generated-plugins.ts, and the new server bootstrap logic.src/test-utils/: A new directory for test-only code. It contains pure mock executors and test execution logic (test-execution.ts) that have no dependencies on the production server.src/utils/: This directory has been purified to contain only side-effect-free, context-agnostic utilities. It no longer exports any server or test-specific code.Lazy Sentry Integration & Async Server Bootstrap:
createServerinsrc/server/bootstrap.ts).import()insrc/server/instrumentation.ts, ensuring it is only imported in production environments and never by tests.XCODEBUILDMCP_SENTRY_DISABLED.DRY Principle & Code Refactoring:
src/utils/axe-command.ts: A new shared utility was created to handle allaxecommand executions. This eliminated ~580 lines of duplicated logic across 10+ UI testing tools.src/utils/system-info.ts: A new shared module was created to centralize system/environment discovery logic, now used by both thedoctortool and Sentry instrumentation.Code Quality and Build Fixes:
eslint.config.jsto correctly ignore allgenerated-*.tsfiles, preventing linting errors in auto-generated code.Testing
doctortool, to align with the new dependency injection patterns and module structure.Notes
This is a foundational architectural improvement that not only fixes a critical CI issue but also makes the codebase more modular, maintainable, and resilient against future contamination between test and production code paths.
Summary by CodeRabbit
New Features
Refactor
Documentation
Tests
Chores